﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using Moq;
using YCMS.Domain.Abstract;
using YCMS.Domain.Entities;
using YCMS.Domain.Concrete;



namespace YCMS.Infrastructure
{
    public class NInjectControllerFactory : DefaultControllerFactory
    {
        private IKernel ninjectKernal;
        private EfDbContext dbContext = new EfDbContext();

        public NInjectControllerFactory()
        {
            ninjectKernal = new StandardKernel();        
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)ninjectKernal.Get(controllerType);
        }

        private void AddBindings()
        {

            //   ninjectKernal.Bind<IProductRepository>().ToConstant(mock.Object);
            ninjectKernal.Bind<IDockRepository>().To<YCMS.Domain.Concrete.EFDockRepository>();
            IDockRepository dockrep = (IDockRepository)ninjectKernal.GetService(typeof(IDockRepository));
            dockrep.Context = dbContext;
            ninjectKernal.Bind<IMemberRepository>().To<YCMS.Domain.Concrete.EFMemberRepository>();
            IMemberRepository memberRep = (IMemberRepository)ninjectKernal.GetService(typeof(IMemberRepository));
            memberRep.Context = dbContext;
        }
    }
}